/*
    利用编译生成的源文件和头文件，测试序列化、反序列化
*/
#include <iostream>
#include "contacts.pb.h"

int main()
{
    std::string peopleInfoStr = "";
    {
        // 定义一个PeopleInfo对象，测试序列化
        contacts::PeopleInfo people;
        people.set_name("张三");
        people.set_age(18);
        if(!people.SerializeToString(&peopleInfoStr))
        {
            std::cout << "序列化失败" << std::endl;
            return -1;
        }
        std::cout << "序列化成功，结果：" << peopleInfoStr << std::endl; 
    }

    {
        // 测试反序列化
        contacts::PeopleInfo people;
        if(!people.ParseFromString(peopleInfoStr))
        {
            std::cout << "反序列化失败" << std::endl;
            return -1;
        }
        std::cout << "反序列化成功，结果：" << people.name() << " " << people.age() << std::endl;
    }
    return 0;
}